package rjeutsky;

import java.sql.Connection;
import java.sql.SQLException;

import rjeutsky.config.ConfigConstants;
import rjeutsky.database.jdbc.Connector;
import rjeutsky.database.jdbc.DatabaseInitializer;
import rjeutsky.ui.ConsoleUi;

public class Lab2Application {
	public static void main(String[] args) {

		if (args.length > 0 && args[0].equals(ConfigConstants.INIT)) {
			initApplication();
		}
		else {
			try {
				ConsoleUi ui = new ConsoleUi();
				ui.setController(new ApplicationController());
				ui.Run();
			} catch (SQLException e) {
				System.err.println(e.getMessage());
			}
		}
	}
	
	private static void initApplication() {
		try {
			Connection connection = new Connector().getConnection();
			DatabaseInitializer initializer = new DatabaseInitializer(connection);
			initializer.Initialize();
			connection.close();
		} catch (Exception ex) {
			System.err.println(ex.getMessage());
		}
	}
}
